home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1993 / MacHack 1993.toast / MacHack™ 1987-1992 / MacHack™ '90 / Utilities ƒ / MPW Tools ƒ / Simula4.07 / Simula 4.07ƒ / SExamples / CopyFile.sim next >
Encoding:
Text File  |  1989-05-02  |  2.8 KB  |  97 lines  |  [TEXT/MPS ]

  1. % -----------------------------------------------------------------------
  2. %    CopyFile
  3. %  This program demonstrate how to use Simula interface to the 
  4. % Standard File Package.
  5. % The program asks for a file to copy, the name of the new file and
  6. % then actually copies the file. The file i/o is done using Simula 
  7. % defined I/O.
  8. % The program excersices the rouitines SFGetFile and SFPutFile
  9. % from class macPackintf. It also usees the class macSFReply that
  10. % holds the result from calling these two procedures respectively.
  11. %
  12. %    Compile the program with the command 
  13. %
  14. %        simcomp CopyFile
  15. %
  16. %    and link it with the following command:
  17. %
  18. %        simld CopyFile -toolbox -APPL
  19. % This sequence can be generated by entering "make copyfile"
  20. %
  21. % -----------------------------------------------------------------------
  22. begin
  23.  
  24.     external class MacPoint="::SInterfaces:MacPoint";
  25.     external class MacSFReply="::SInterfaces:MacSFReply";
  26.     external class MacPackIntf="::SInterfaces:MacPackIntf";
  27.  
  28.     ref(MacPackIntf) myMacPackIntf; ! Needs one of these ;    
  29.     ref(MacSFReply) myMacSFReply;   ! Will hold the result from ; 
  30.                                               ! calls to PackInf ;
  31.     ref(MacPoint) LeftUpperCorner;  ! Placement of dialog box ;
  32.     
  33.     ref(outfile) myOutFile; ! simula files - used to copy ;
  34.     ref(infile) myInFile;
  35.     text array TypeList(0:0);    ! A TypeList has to be a one dimensional
  36.                                         ! text array with lowerindex = 0 and
  37.                                         ! upperindex <= 3. Every element
  38.                                         ! has to be a four character text.;
  39.         
  40.     LeftUpperCorner:-new MacPoint;    ! LeftUpperCorner of Dialog Window;
  41.     LeftUpperCorner.h:=20;
  42.     LeftUpperCorner.v:=20;
  43.  
  44.     myMacPackIntf:- new MacPackIntf;
  45.     TypeList(0):-copy("TEXT");    
  46.     myMacSFReply:-new MacSFReply;    
  47.     myMacPackIntf.SFGetFile(LeftUpperCorner,notext,
  48.         0,1,TypeList,0,myMacSFReply);
  49.     inspect myMacSFReply do
  50.     begin
  51.         if Good then
  52.         begin
  53.             myInFile:-new infile(fname);
  54.             if not myInFile.open(blanks(132)) then
  55.                 Error("The infile could not be opened");
  56.         end
  57.         else
  58.             Error("No infile");
  59.     end;
  60.  
  61.     myMacPackIntf.SFPutFile(LeftUpperCorner,"Save document as", 
  62.         notext, 0, myMacSFReply);        
  63.     inspect myMacSFReply do
  64.     begin
  65.         if Good then
  66.         begin
  67.             myOutfile:-new outfile(fname);
  68.             if not myOutfile.open(blanks(132)) then
  69.                 Error("The outfile could not be opened");
  70.         end
  71.         else
  72.             Error("No outfile");
  73.     end;
  74.     
  75.     begin
  76.         boolean longimage; ! result of inrecord: true
  77.                            ! if image was filled but
  78.                                  ! no line-terminater was found.;
  79.     ! -- use same image - no internal copying needed!--;
  80.         myOutfile.image:-myInFile.image;
  81.     
  82.         longimage:=myInfile.inrecord;
  83.         while not myInFile.endfile do
  84.         begin
  85.             myOutfile.setpos(myInfile.pos);
  86.             if longimage then
  87.                 myOutfile.outrecord
  88.             else 
  89.                 myOutfile.outimage;
  90.             longimage:=myInfile.inrecord;
  91.         end;
  92.     end - inner block --;
  93.     myInFile.close;
  94.     myOutFile.close;
  95. end;